<template>
  <el-container class="home-container">
    <el-header>
      <div>
        <img src="../../assets/img/logo02.png" width="240" height="70" />
        <span>汽车总动员</span>
      </div>
      <el-dropdown @command="handleCommand">
              <span class="el-dropdown-link">
<!--                  <el-avatar :src="avatar"></el-avatar>-->
                <el-avatar >
                  <img :src="imgUrl"/>
                </el-avatar>
              </span>
        <span style="color: white">{{loginName}}</span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="a">个人信息</el-dropdown-item>
          <el-dropdown-item command="b">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>

    </el-header>
    <el-container>
      <el-aside :width="isCollapse? '64px' : '210px'">
        <div class="toggle" @click="toggleCollage">|||</div>
        <el-menu
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409EFF"
            :unique-opened="true"
            :collapse="isCollapse"
            :collapse-transition="istransition"

            :router="true"
            :default-active="activePath"
        >
          <el-submenu :index="index+''" v-for="(item,index) in leftMenu">
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{item.menuName}}</span>
            </template>
            <el-menu-item :index="subitem.url"  class="el-icon-menu" v-for="(subitem,index) in item.children">{{subitem.menuName}}</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view/>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data(){
    return {
      leftMenu:[],
      isCollapse:false,
      istransition:false,
      activePath:'',
      avatar:'',
      //登录人的头想路径
      imgUrl:'',
      //登录人的名称
      loginName:''
    }
  },
  created() {
    var that=this;
    this.$http.get("/sys/menu/leftMenus").then(function(resp){
      that.leftMenu=resp.data.data.leftMenus;
      that.imgUrl=resp.data.data.user.avatar;
      that.loginName=resp.data.data.user.loginName;
    })
  },
  methods:{
    toggleCollage(){
      this.isCollapse=!this.isCollapse
    },
    handleCommand(command) {
      var that = this;
      if (command=="a"){
        //that.$message("个人信息");
        that.$router.push("/personal");
      }else if (command=="b"){
        sessionStorage.clear();
        that.$router.push("/login");
      }
    }
  }
}
</script>

<style scoped>
.home-container {
  height: 100%;
}
.el-header {
  background-color: #373d41;
  display: flex;
  justify-content: space-between;
  padding-left: 0px;
  align-items: center;
  color: #fff;
  font-size: 20px;
}
.el-header > div {
  display: flex;
  align-items: center;
}
.el-header > div > span {
  margin-left: 15px;
}
.el-aside {
  background-color: #333744;

}
.el-aside .el-menu{
  border:none;
  text-align: left;
}
.el-main {
  background-color: #eaedf1;
}
.toggle{
  background-color: #4A5064;
  color: #fff;
  line-height: 24px;
  font-size: 10px;
  text-align: center;
  letter-spacing: 5px;
  cursor: pointer;
}
.el-menu-item{
  margin-left: 25px;
  text-align: left;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409EFF;
}
.el-icon-arrow-down {
  font-size: 12px;
}
</style>